<?php
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
include '../../operations/connection.php';	
include 'substring-comment.php';
$id = $_REQUEST['idproject'];
$id_employee = $_REQUEST['idemp'];
$newlang = $_REQUEST['newlang'];
		
		if ($_REQUEST['newlang'] == "EN") {
			include "../../value/value_en.php";
		} else if($_REQUEST['newlang'] == "VN") {
			include "../../value/value_vn.php";
		}
		else {
			include "../../value/value_kr.php";
		}

$page = isset ( $_REQUEST["page"] ) ? intval ( $_REQUEST["page"] ) : 1;

$rows_per_page = 20;

$page_start = ( $page - 1 ) * $rows_per_page;
$page_end = $page * $rows_per_page; 
$queryListErrorByIDPr = mysql_query("SELECT tp.IDTest, tp.Title, tp.TextTest, tp.Time, tp.`Status`, tp.`Correct`,e.FullName,
				tp.IDTestTemp,pp.IDView,pp.NameProject,pc.backgroundColor,pc.backgroundConfirm,tp.Comment_Last,tp.NameEmployee_Last 
			   FROM pr_testproject tp, employee e ,pr_project pp,priority_color pc  WHERE pp.IDProject = tp.IDProject AND tp.IDProject = '$id' AND e.IDEmployee = tp.IDEmployee 
			    AND pc.id = tp.IdPriorityColor ORDER BY tp.`Status`=2 ASC,tp.DateConfirm DESC,tp.IdPriorityColor DESC,tp.Time DESC LIMIT $page_start,$rows_per_page ");

 
			while ($row=mysql_fetch_array($queryListErrorByIDPr)){
				$timecurrent = time() - (30*24*60*60);
				
			 	$converttimetestpro = strtotime($row[Time]);
			 	
			 	if($timecurrent > $converttimetestpro){
			 		$sqlcomment = "DELETE FROM pr_comment WHERE pr_comment.IDTestProject = '$row[IDTest]'";
					mysql_query($sqlcomment);
														
					$sqldelete = "DELETE FROM pr_testproject WHERE pr_testproject.IDTest = '$row[IDTest]'";
					mysql_query($sqldelete);
					
					
			 	}}
$queryListErrorByIDPr = mysql_query("SELECT pr.IDManager , tp.IDTest, tp.IDProject, tp.IDEmployee, tp.Title, tp.TextTest, tp.Time, tp.`Status`,e.FullName,tp.`Delete`,tp.IDTestTemp,
			   (select c.Comment from pr_comment c, employee e 
									 where c.IDEmployee = e.IDEmployee and c.IDTestProject = tp.IDTest order by c.DateComment DESC limit 1) as Comment_C,
			   (select e.FullName from pr_comment c, employee e 
									 where c.IDEmployee = e.IDEmployee and c.IDTestProject = tp.IDTest order by c.DateComment DESC limit 1) as FullName_C
									 
			   FROM pr_testproject tp, employee e,pr_project pr WHERE pr.IDProject = tp.IDProject AND tp.IDProject = '$id' AND e.IDEmployee = tp.IDEmployee 
			   AND tp.`Delete` = 1 ORDER BY IDTest DESC LIMIT $page_start,$rows_per_page ");
$re = mysql_query("SELECT tp.IDTest, tp.IDProject, tp.IDEmployee, tp.Title, tp.TextTest, tp.Time, tp.`Status`,e.FullName,tp.`Delete`,tp.IDTestTemp 
			   		FROM pr_testproject tp, employee e WHERE tp.IDProject = '$id' AND e.IDEmployee = tp.IDEmployee 
			  		 AND tp.`Delete` = 1 ORDER BY IDTest DESC");
				 $number_of_page = ceil ( mysql_num_rows( $re ) / $rows_per_page ); 

?>
<a class="caption"><?php echo $l_list_error?> </a>
		<div class="divError divinvi" >
			<div class="rf-p divListError">
				<ul>
					<li><a  class="linkAction" href="project_admin.php?content=admin/project/project-detail.php&id=<?=$id?>&tab=1">
						<img src="images/list.png" alt="" />
						<span
							style="display: inline-block; width: 100%"><?php echo $l_error?>
						</span> </a></li>
					<li style="left: 150px"><a  class="linkAction" href="project_admin.php?content=admin/project/project-detail.php&id=<?=$id?>&tab=2"><img
							src="images/recyclebin_empty.png" alt="" /><span
							style="display: inline-block; width: 100%"><?php echo $l_reclycle?>
						</span> </a></li>
					<li style="left: 150px"><a  class="linkAction" href="project_admin.php?content=admin/project/project-detail.php&id=<?=$id?>&tab=1"><img
							src="images/reload.png" alt="" /><span
							style="display: inline-block; width: 100%"><?php echo $l_refresh?>
						</span> </a></li>
			<li style="float: right;width: auto;text-align: right;padding: 20px 20px">
						<a href="#" onclick="if(confirm('<?php echo $l_confirm_deleteproject?>')){ processEmptyError(<?=$id?>,<?=$id_employee?>,1,this);return true;}else{return false;}">[ Empty Error]</a></li>
				</ul>
			</div>
			
			<div id='ajaxdelete'>
<table width="100%" class="rf-dt" id="report">
			<?php 
			if (mysql_num_rows( $queryListErrorByIDPr )<=0) {
			?>
			<tr style="background: #f2f9ff" >
				<td colspan="5" style="padding: 10px"><?=$l_list_emplty?></td>
			</tr>
			<?php }else{
			 
			$i = 0;
			while ($row=mysql_fetch_array($queryListErrorByIDPr)){
				$i++;
				$idtestproject = $row[IDTest];
				$idemplTestpro = $row[IDEmployee];
				$prdelete = $row[Delete];
				$titletestpro = $row[Title];
				$contenttestpro = $row[TextTest];
				$fullnames = $row[FullName];
				$time = $row[Time];
				$indexcomment = (($page-1)*20)+$i;
				
				$stringcolortest = substr($row[Title],0,-14);
				$color = substr($row[Title],-6);
				
				
				$stringcolor = substr($row['Comment_Last'],0,-14);
				
				
				//tag html tranh be giao dien
				$stringcolor = strip_tags($stringcolor);
				$idtesppr_temp = $row[IDTestTemp];
				?>
				
				<tr style="background: #f2f9ff" >
					<td class="rf-dt-c"
						style="width: 5%; vertical-align: middle; text-align: center;min-width: 5%"><?php echo $indexcomment;?>
					</td>
					<td class="rf-dt-c"
						style="width: 9%; vertical-align: middle; text-align: center;min-width: 9%"><?php echo $idtesppr_temp;?>
					</td>
					
					<td class="rf-dt-c" 
						style="padding: 7px; vertical-align: middle; width: 50%;">
						<div class="rowMinHeight" align="left" style="width: 97%;">
							<span onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='default'" onclick="showcommanderrorRecyclebin(<?=$indexcomment?>,'<?=$idtestproject?>','<?=$id_employee?>','<?=$id?>',1, this,'<?=$page?>');" class="titleError"> 
							<a class="bclick" style="color: #424242;cursor:pointer"> 
							<?php 
							if(strlen($stringcolortest)==0){?>
								<font color="#6290ff"><?php echo  $titletestpro ?> </font>
							<?php 
							}
							switch ($color){
								case 'B023AB':
									?> <font color="#B023AB"><?php echo  $stringcolortest ?> </font> <?php	break;
								case '424242':
									?> <font color="#424242"><?php echo  $stringcolortest ?> </font> <?php	break;
								case '3DA850':
									?><font color="#3da850"><?php echo  $stringcolortest ?> </font> <?php	break;
								case 'B02323':
									?><font color="#B02323"><?php echo  $stringcolortest ?> </font> <?php	break;
								default:
									?> <font color="#424242"><?php echo  $stringcolortest ?> </font> <?php	break;
															}?> </a> </span>
							<div class="writeBy">
							
								<div align="right" style="width: 99%; float: left;">
								<span><?php include_once 'substring-comment.php';?>
								<?php 
								
								if (strlen($stringcolor)==0){
									$a=explode('<br>',$row['Comment_Last']);
									echo substringProvider::catchuoi($a[0],27);
								}else{
									$a=explode('<br>',$stringcolor);
									echo substringProvider::catchuoi($a[0],27);
								}
								
								?>
								</span> 
								<span style="font-weight: bold;"><?php  if ($row['NameEmployee_Last']!="") {
										echo '('.$row['NameEmployee_Last'].')';
										}?>
								</span>	
								</div>
							</div>
						</div>
					</td>
					<td class="rf-dt-c"
						style="vertical-align: middle; text-align: center; width: 11%;">
						<?php echo $fullnames?></td>
					<td class="rf-dt-c"
						style="vertical-align: middle; text-align: center; width: 10%;"><?php echo $time?>
					</td>
					<td class="rf-dt-c" style="vertical-align: middle; width: 15%;">
					<div
							class="divInButton" style="text-align: center;">
							<span onmouseover="this.style.cursor='pointer'" title="<?php echo $l_restore?>" onmouseout="this.style.cursor='default'" style="width:60px; cursor:pointer" onclick="if(confirm('<?php echo $l_confirm_deleteproject?>')){ active_test_project('<?=$idtestproject?>','<?=$id?>','<?=$id_employee?>','<?=$page?>',this); return true;}else{return false;}">
									<img src="images/p-active.png"  style="width: 32px;cursor: pointer;" alt="Active" />
								</span>

								<span onmouseover="this.style.cursor='pointer'" title="<?php echo $l_delete?>" onmouseout="this.style.cursor='default'" style="width: 60px" 
								onclick="if(confirm('<?php echo $l_confirm_deleteproject?>')){ delete_test_project_recyclebin('<?=$prdelete?>','<?=$idtestproject?>','<?=$id?>','<?=$id_employee?>','<?=$page?>',this); return true;}else{return false;}" >
									<img src="images/p-delete.png"  style="width: 32px;cursor: pointer;"
									alt="<?php echo $l_delete?>" />

								</span>
							
						</div>	
					</td>
				</tr>
				
				
				
				<tr style="background: #f2f9ff; display:none" id="commentprojecthide" >
				</tr>
				
				<?php }}?>
				
				
			<tr class="trfoot">
                    	<td class="rf-dt-ftr-c" scope="colgroup" colspan="6">
                        	<div style="text-align: center; width: 100%">
				<?php 
				
				 $max_page = 10;
				 if ( $number_of_page > 1 ) { 
					 
				 	if($page!=1){?>
						<a href="project_admin.php?content=admin/project/project-detail.php&id=<?=$id?>&tab=2&page=<?=1?>">
					 		<span class="button_next" style="border:none"><?php echo "<<<<"?></span></a> 
					 	<a href="project_admin.php?content=admin/project/project-detail.php&id=<?=$id?>&tab=2&page=<?=($page-1)?>">
					 		<span onmouseover="" class="button_next" style="border:none"><?php echo "<<"?></span></a> 
					<?php  }
					else{
						echo "<span class='button_next' style='cursor:default'><<<</span>"; 
						echo "<span class='button_next' style='cursor:default'><<</span>";
					} 
					if (!isset($_SESSION['prevstart'])) {
						$_SESSION['prevstart'] = 1;
					}
					
					if ($max_page < $number_of_page){
						if ($page<=1) {
							$_SESSION['prevstart'] = 1;
						}		
						elseif ($page>=$number_of_page) {
							$_SESSION['prevstart'] = $number_of_page-$max_page+1;
						}	
						elseif ($page<=$_SESSION['prevstart']) {
							$_SESSION['prevstart'] = $page - 1;
						}elseif ($page>=$_SESSION['prevstart']+$max_page-1) {
							$_SESSION['prevstart'] = $page - $max_page + 2;
							
						}		
					 	
					}
					$startpage = $_SESSION['prevstart'];
					$endpage = $max_page + $startpage;
					for ($i=$startpage ;$i<$endpage && $i<=$number_of_page; $i++) {
					 	if ($i == $page) {
				     	 	?><span class="button_next" style="border:none; cursor:default;"><b><?php echo $i;?></b></span><?php 
						}else {
				     		?><a href="project_admin.php?content=admin/project/project-detail.php&id=<?=$id?>&tab=2&page=<?=$i?>">
				     	 		<span class="button_next" style="border:none;color: #508e21;" ><b><?php echo $i;?></b></span></a> <?php 
				   		}
					}
				
					 if($page!=$number_of_page){ ?>
						<a href="project_admin.php?content=admin/project/project-detail.php&id=<?=$id?>&tab=2&page=<?=($page+1)?>">
					 		<span class="button_next" style="border:none"><?php echo ">>"?> </span></a>
					 	<a href="project_admin.php?content=admin/project/project-detail.php&id=<?=$id?>&tab=2&page=<?=$number_of_page?>">
					 		<span class="button_next" style="border:none"><?php echo ">>>"?> </span></a><?php ;}
					else{
						echo "<span class='button_next' style='cursor:default'>>></span> ";
						echo "<span class='button_next' style='cursor:default'>>>></span> ";
					}
				}
				?>
				</div>
				</td>
				</tr> 
			</table>
			</div>
			</div>
<?mysql_close($connection);?>